package org.dyk.mallmanagementsystem.repository;

import org.dyk.mallmanagementsystem.model.Goods;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface GoodsRepository extends CrudRepository<Goods,Integer> {
    //查询所有商品，并分页
    public Page<Goods> findAll(Pageable pageable);

    //查询所有商品
    public List<Goods> findAll();

    //根据 主键 获取商品信息
    public Goods findByGid(int gid);

    //根据商品名获取商品信息
    public Goods findByGoodsName(String goodsName);

    //获取相同分类商品信息
    public List<Goods> findByTid(int tid);

    //自定义查询商品
    @Query(nativeQuery = true, value = "select * from goods where " +
            "if(?1 != '', goods_name like %?1%, 1=1) and if(?2 != 0,tid = ?2,1=1)")
    public List<Goods> selectByGoods(String goodsName, int tid);
}
